package com.seckill.rabbitmq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MQReceiver {

    @RabbitListener(queues = "queue")
    public void receive(Object msg) {
        log.info("接收消息：{}", msg);
    }

    @RabbitListener(queues = "queue-fanout01")
    public void receive01(Object msg) {
        log.info("QUEUE01接收消息：{}", msg);
    }

    @RabbitListener(queues = "queue-fanout02")
    public void receive02(Object msg) {
        log.info("QUEUE02接收消息：{}", msg);
    }

    @RabbitListener(queues = "queue-direct01")
    public void receive03(Object msg) {
        log.info("QUEUE03接收消息：{}", msg);
    }

    @RabbitListener(queues = "queue-direct02")
    public void receive04(Object msg) {
        log.info("QUEUE04接收消息：{}", msg);
    }

    @RabbitListener(queues = "queue-topic01")
    public void receive05(Object msg) {
        log.info("QUEUE05接收消息：{}", msg);
    }

    @RabbitListener(queues = "queue-topic02")
    public void receive06(Object msg) {
        log.info("QUEUE06接收消息：{}", msg);
    }

    @RabbitListener(queues = "queue-header01")
    public void receive07(Message msg) {
        log.info("QUEUE07接收Message对象：{}", msg);
        log.info("QUEUE07接收消息：{}", new String(msg.getBody()));
    }

    @RabbitListener(queues = "queue-header02")
    public void receive08(Message msg) {
        log.info("QUEUE08接收Message对象：{}", msg);
        log.info("QUEUE08接收消息：{}", new String(msg.getBody()));
    }
}
